package com.gxa.controller.investment;

import com.gxa.common.utils.Result;
import com.gxa.dto.investmentDto.IntentionRegisterQuitDto;
import com.gxa.entity.investment.IntentionRegister;
import com.gxa.entity.investment.Project;
import com.gxa.service.investment.IntentionRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 意向登记表 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-17 03:52:28
 */
@Api(tags = "过程管理/意向登记")
@RestController
@RequestMapping("/intention/register")
public class IntentionRegisterController {
    @Autowired
    private IntentionRegisterService intentionRegisterService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("列表接口(条件查询出问题时使用)")
    @GetMapping("/list")
    public Result seletAll(){
        try {
            return Result.success(intentionRegisterService.seletAll());
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("seletAll");
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("增加接口")
    @PostMapping("/add")
    public Result add(IntentionRegister intentionRegister){
        System.out.println(intentionRegister.getStartDate());
        try {
            intentionRegisterService.add(intentionRegister);
            return Result.success("add success");
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("add failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑接口")
    @PutMapping("/update/{id}/{state}")
    public Result update(@PathVariable("id") Integer id, @PathVariable("state") Integer state){
        try {
            intentionRegisterService.updateToState(id, state);
            return Result.success("update success");
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("update failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按id查询")
    @GetMapping("/quit/{id}")
    public Result quitById(@PathVariable("id") Integer id){
        try {
            return Result.success(intentionRegisterService.quitById(id));
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("quitById failed");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按条件查询")
    @PostMapping("/quit")
    public Result quit(@RequestBody IntentionRegisterQuitDto intentionRegisterQuitDto, Integer pageNum,Integer pageSize){
        try {
            return Result.success(intentionRegisterService.queryList(intentionRegisterQuitDto, pageNum, pageSize));
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.failed("query failed");
    }
}
